package ATMBankSimulationSystem;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
//半成品，不想写了;
public class Demo {

	public static TreeMap<String, String> treemap = new TreeMap<String, String>();
	public static String account = null;
	public static int entry_state = 0;
	public static int register_state = 0;

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		while (true) {
			System.out.println("欢迎来到ATM自动系统\n" + "登录和注册\r\n" + "1、注册 \r\n" + "2、登录\r\n" + "若您已拥有账号，请选择如下操作 \r\n"
					+ "3、存款功能 \r\n" + "4、取款功能 \r\n" + "5、转账功能 \r\n" + "6、查询功能 \r\n" + "7、注销账号\r\n" + "8、修改密码\r\n"
					+ "9、退出 \n" + "请选择您需要的服务：");
			while (true) {
				int choise = input.nextInt();
				if (choise == 1) {
					register();
					break;
				} else if (choise == 2) {
					entry();
					break;
				} else if (choise == 3) {
					deposit();
					break;
				} else if (choise == 4) {
					withdraw();
					break;
				} else if (choise == 5) {
					transferAccounts();
					break;
				} else if (choise == 6) {
					search();
					break;
				} else if (choise == 7) {
					dropAccount();
					break;
				} else if (choise == 8) {
					updatePassword();
					break;
				} else if (choise == 9) {
					System.out.println("欢迎再次使用");
					System.exit(0);
				} else {
					System.out.println("您输入的数字无效，请重新输入:");
					break;
				}
			}

		}

	}

	private static void updatePassword() {
		// TODO Auto-generated method stub

	}

	private static void dropAccount() {
		// TODO Auto-generated method stub

	}

	private static void search() {
		// TODO Auto-generated method stub

	}

	private static void transferAccounts() {
		// TODO Auto-generated method stub

	}

	private static void withdraw() {
		// TODO Auto-generated method stub

	}

	private static void deposit() {
		// TODO Auto-generated method stub

	}

	private static void entry() {
		Scanner input = new Scanner(System.in);

		if (entry_state == 1) {
			System.out.println("您已经登陆");
			return;
		}

		System.out.println("请输入您的账号:");
		
		account = input.nextLine();
		String password;

		Set<String> key = treemap.keySet();

		pw: for (int i = 0;;) {
			for (String acc : key) {
				if (i > 0) {
					account = input.nextLine();
				}
				if (acc.equals(account)) {
					break pw;
				} else {
					System.out.println("您输入的账号不存在，请重新输入");
					i++;
					break;
				}
			}
		}
		System.out.println("请输入密码");
		password = input.nextLine();
		for (int i = 0;; i++) {
			if (i > 0) {
				password = input.nextLine();
			}
			if (password.equals(treemap.get(account))) {
				System.out.println("密码正确，欢迎使用");
				break;
			} else {
				i++;
				System.out.println("您输入的密码有误，请重新输入");

			}
		}
		entry_state = 1;

	}

	private static void register() {
		Scanner input = new Scanner(System.in);
		System.out.println("请创建您的账号名字");
		String account = null;

		while (true) {

			account = input.nextLine();

			if (treemap.containsKey(account)) {
				System.out.println("您输入的账号已存在，请重新输入");
				register_state = 1;

			}else {
				register_state = 0;
			}
			
			if (register_state == 0) {
				break;
			}

		}

		String password;
		System.out.println("请输入您的密码");
		password = input.nextLine();
		while (true) {
			System.out.println("请再次输入您的密码");
			String password2 = input.nextLine();
			if (password.equals(password2)) {
				System.out.println("创建账号成功");

				break;
			} else {
				System.out.println("您输入的密码有误");
			}
		}

		treemap.put(account, password);
		

//		Set<String> key = treemap.keySet();
//		for(String k : key) {
//			String v= treemap.get(k);
//			System.out.println(k+v);
//		}
	}

}
